/**
 * Copyright 1998-2010 Epic Games, Inc. All Rights Reserved.
 */
class BloodMagicWeapon extends UTBeamWeapon;

simulated function PostBeginPlay()
{
	AttachWeaponTo(Instigator.Mesh,'WeaponPoint');
	super.PostBeginPlay();
}

simulated function AttachWeaponTo(SkeletalMeshComponent MeshCpnt, optional Name SocketName)
{
	MeshCpnt.AttachComponentToSocket(mesh,SocketName);
}

simulated function ProcessInstantHit(byte FiringMode, ImpactInfo Impact, optional int NumHits)
{
    WorldInfo.MyDecalManager.SpawnDecal
    (
		DecalMaterial'HU_Deck.Decals.M_Decal_GooLeak',	// UMaterialInstance used for this decal.
		Impact.HitLocation,	                            // Decal spawned at the hit location.
		rotator(-Impact.HitNormal),	                    // Orient decal into the surface.
		128, 128,	                                    // Decal size in tangent/binormal directions.
		256,	                                        // Decal size in normal direction.
		false,	                                        // If TRUE, use "NoClip" codepath.
		FRand() * 360,	                                // random rotation
		Impact.HitInfo.HitComponent                     // If non-NULL, consider this component only.
    );               
}

simulated function Projectile ProjectileFire()
{
	local vector		RealStartLoc, AimDir;
	local Projectile	SpawnedProjectile;

	// tell remote clients that we fired, to trigger effects
	IncrementFlashCount();

	if( Role == ROLE_Authority )
	{
		AimDir = Vector(Instigator.Rotation);
		`log(AimDir);
		// this is the location where the projectile is spawned.
		RealStartLoc = GetPhysicalFireStartLoc(AimDir);

		// Spawn projectile
		SpawnedProjectile = Spawn(GetProjectileClass(), Self,, RealStartLoc);
		if( SpawnedProjectile != None && !SpawnedProjectile.bDeleteMe )
		{
			SpawnedProjectile.Init( AimDir );
		}

		// Return it up the line
		return SpawnedProjectile;
	}

	return None;
}

/*********************************************************************************************
 * State WeaponFiring
 * See UTWeapon.WeaponFiring
 *********************************************************************************************/

simulated state WeaponBeamFiring
{
	/**
	 * When done firing, we have to make sure we unlink the weapon.
	 */
	simulated function EndFire(byte FireModeNum)
	{
		super.EndFire(FireModeNum);
	}

	simulated function SetCurrentFireMode(byte FiringModeNum)
	{
		local byte InstigatorFireMode;

		CurrentFireMode = FiringModeNum;

		// on the pawn, set a value of 2 if we're linked so the weapon attachment knows the difference
		// and a value of 3 if we're not linked to anyone but others are linked to us
		if (Instigator != None)
		{
			InstigatorFireMode = CurrentFireMode;
			Instigator.SetFiringMode(Self, InstigatorFireMode);
		}
	}

	function SetFlashLocation(vector HitLocation)
	{
		Global.SetFlashLocation(HitLocation);
		// SetFlashLocation() resets Instigator's FiringMode so we need to make sure our overridden value stays applied
		SetCurrentFireMode(CurrentFireMode);
	}

	/**
	 * Update the beam and handle the effects
	 * FIXMESTEVE MOVE TO TICKSPECIAL
	 */
	simulated function Tick(float DeltaTime)
	{
		// Retrace everything and see if there is a new LinkedTo or if something has changed.
		UpdateBeam(DeltaTime);
	}

	simulated function BeginState(Name PreviousStateName)
	{
		Super.BeginState(PreviousStateName);
	}

	simulated function EndState(Name NextStateName)
	{
		//local color EffectColor;
		//local LinearColor LinEffectColor;

		Super.EndState(NextStateName);

		//// reset material and muzzle flash to default color
		//LinkAttachmentClass.static.GetTeamBeamInfo(255, EffectColor);
		//if (WeaponMaterialInstance != None)
		//{
		//	LinEffectColor = ColorToLinearColor(EffectColor);
		//	WeaponMaterialInstance.SetVectorParameterValue('TeamColor', LinEffectColor);
		//}
		//if (MuzzleFlashPSC != None)
		//{
		//	MuzzleFlashPSC.ClearParameter('Link_Beam_Color');
		//}
	}


	/** You can run around spamming the beam and needing to look around all speed **/
	simulated function bool CanViewAccelerationWhenFiring()
	{
		return TRUE;
	}
}


defaultproperties
{

	FiringStatesArray(0)= WeaponFiring //We don't need to define a new state
    WeaponFireTypes(0)= EWFT_Projectile
    FireInterval(0)= 0.4
    Spread(0)=0
	//FireOffset=(X=0,Y=50,Z=-60);

	//// Weapon SkeletalMesh
	 Begin Object class=SkeletalMeshComponent Name=BloodMagicMesh
		SkeletalMesh=SkeletalMesh'WP_LinkGun.Mesh.SK_WP_LinkGun_3P'
		HiddenGame=FALSE 
		HiddenEditor=FALSE

	 End object

	WeaponProjectiles(0)=class'UTProj_LinkPlasma' // UTProj_LinkPowerPlasma if linked (see GetProjectileClass() )

	/////////////////////////////////////////
	//PickupSound=SoundCue'A_Pickups.Weapons.Cue.A_Pickup_Weapons_Link_Cue'

	//AmmoCount=100
	//LockerAmmoCount=100
	//MaxAmmoCount=100//Instigator.HealthMax
	//MomentumTransfer=50000.0
	//BeamAmmoUsePerSecond=8.5
	//MinimumDamage=5.0

	EffectSockets(0)=MuzzleFlashSocket
	EffectSockets(1)=MuzzleFlashSocket

	//BeamPreFireAnim(1)=WeaponAltFireStart
	//BeamFireAnim(1)=WeaponAltFire
	//BeamPostFireAnim(1)=WeaponAltFireEnd

	//MuzzleFlashSocket=MuzzleFlashSocket
	//MuzzleFlashPSCTemplate=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_MF_Primary'
	//MuzzleFlashAltPSCTemplate=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_MF_Beam'
	//bMuzzleFlashPSCLoops=true
	//MuzzleFlashLightClass=class'UTGame.UTLinkGunMuzzleFlashLight'

	//bShowAltMuzzlePSCWhenWeaponHidden=TRUE

	//TeamMuzzleFlashTemplates[0]=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_MF_Beam_Red'
	//TeamMuzzleFlashTemplates[1]=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_MF_Beam_Blue'
	//TeamMuzzleFlashTemplates[2]=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_MF_Beam'
	//HighPowerMuzzleFlashTemplate=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_MF_Beam_Gold'

	//MuzzleFlashColor=(R=120,G=255,B=120,A=255)
	//MuzzleFlashDuration=0.33;

	//BeamTemplate[1]=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Altbeam'
	//BeamSockets[1]=MuzzleFlashSocket02
	//EndPointParamName=LinkBeamEnd

	//IconX=412
	//IconY=82
	//IconWidth=40
	//IconHeight=36

	//StartAltFireSound=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_AltFireStartCue'
	//EndAltFireSound=SoundCue'A_Weapon_Link.Cue.A_Weapon_Link_AltFireStopCue'

	/////////////////////////////////////////

	//////////////////////////////////////////////////
	//LinkBeamColors(0)=(R=255,G=64,B=64,A=255)
	//LinkBeamColors(1)=(R=64,G=64,B=255,A=255)
	//LinkBeamColors(2)=(R=128,G=220,B=120,A=255)
	//HighPowerBeamColor=(R=192,G=192,B=32,A=255)

	//LinkBeamSystems[0]=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Altbeam_Red'
	//LinkBeamSystems[1]=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Altbeam_Blue'
	//LinkBeamSystems[2]=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Altbeam'

	//HighPowerSystem=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Altbeam_Gold'

	//TeamBeamEndpointTemplates[0]=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Beam_Impact_Red'
	//TeamBeamEndpointTemplates[1]=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Beam_Impact_Blue'
	//TeamBeamEndpointTemplates[2]=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Beam_Impact'
	//HighPowerBeamEndpointTemplate=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Beam_Impact_Gold'

	//TeamMuzzleFlashTemplates[0]=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_3P_Beam_MF_Red'
	//TeamMuzzleFlashTemplates[1]=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_3P_Beam_MF_Blue'
	//TeamMuzzleFlashTemplates[2]=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_3P_Beam_MF'
	//HighPowerMuzzleFlashTemplate=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_3P_Beam_MF_Gold'

	//MuzzleFlashSocket=MussleFlashSocket
	//MuzzleFlashPSCTemplate=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_3P_Primary_MF'
	//MuzzleFlashAltPSCTemplate=ParticleSystem'WP_LinkGun.Effects.P_FX_LinkGun_3P_Beam_MF'
	//MuzzleFlashColor=(R=120,G=255,B=120,A=255)
	//MuzzleFlashDuration=0.33
	//bMuzzleFlashPSCLoops=true
	//MuzzleFlashLightClass=class'UTLinkGunMuzzleFlashLight'

	//BeamTemplate[1]=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Altbeam'
	//BeamSockets[1]=MussleFlashSocket02

	//EndPointParamName=LinkBeamEnd
	//WeaponClass=class'UTWeap_LinkGun'
	//WallHitTemplate=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Beam_Impact_HIT'

	//ConnectionEffectTemplate=ParticleSystem'WP_LinkGun.Effects.P_WP_Linkgun_Connection_Beam'

	//BeamDecal=MaterialInstanceTimeVarying'WP_FlakCannon.Decals.MITV_WP_FlakCannon_Impact_Decal01' 
	//DecalWidth=32.0
	//DecalHeight=32.0
	//DecalDissolveParamName="DissolveAmount"
	//DurationOfDecal=20.0
	//TicksBetweenDecals=0
	///////////////////////////////////////////////


	//Load the Mesh
	Mesh=BloodMagicMesh
	Components.Add(BloodMagicMesh)
}
